package com.spring.sperapc.web.service.impl;




import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;

import com.spring.security.web.dao.UserMapper;
import com.spring.sperapc.web.dao.FamilyMemberMapper;
import com.spring.sperapc.web.dao.UserDetailMapper;
import com.spring.sperapc.web.model.FamilyMember;
import com.spring.sperapc.web.service.FamilyMemberService;

/**
 * Created by wojunyu on 2015/8/12.
 */
@Service
public class FamilyMemberServiceImpl implements FamilyMemberService{
    @Resource
    private FamilyMemberMapper familyMemberMapper;

    @Resource
    private UserMapper userMapper;
    
    @Resource
    private UserDetailMapper userDetailMapper;

    @Override
    public int deleteByPrimaryKey(@Param(value = "id") String id) {
        return familyMemberMapper.deleteByPrimaryKey(id);
    }

    /**
     * 新增家庭成员
     */
    @Override
    public int insertSelective(FamilyMember record) {
        int ret = 0;
        int fm = familyMemberMapper.insertSelective(record);
        if(fm==1){
            ret = 1;
        }
        return ret;
    }

//    @Override
//    public FamilyMember selectByPrimaryKey(Map m) {
//        return familyMemberMapper.selectByPrimaryKey(m);
//    }

    @Override
    public List<FamilyMember> selectByFamilyId(Map m) {
        return familyMemberMapper.selectByFamilyId(m);
    }

    @Override
    public int updateByPrimaryKeySelective(FamilyMember record) {
    	int ret = 0;
    	int fmi = familyMemberMapper.updateByPrimaryKeySelective(record);
//    	String ud_id = familyMemberMapper.selectUDIdByUFMId(record.getId());
//    	if(!ApplicationUtils.isNotNull(ud_id)){
//    		return fmi;
//    	}
    	//生成用户详细信息
//        UserDetail ud = new UserDetail();
////        ud.setId(ud_id);
//        ud.setBirthday(record.getBirthday());
//        ud.setSex(record.getSex());
//        ud.setName(record.getName());
//        int udi = userDetailMapper.updateByPrimaryKeySelective(ud);
        if(fmi==1){
            ret = 1;
        }
        return ret;
    }
}
